@extends('common.admin-master')

@section('html-body')

    <div class="content">

        <div class="header">
            <div class="stats">
                <p class="stat"><a href="#new_creater" data-toggle="tab">添加投资机构</a></p>
                <p class="stat"><a href="#creater_list" data-toggle="tab">返回首页</a></p>
            </div>
            <h1 class="page-title">用户管理</h1>
        </div>

        <ul id="myTab" class="nav nav-tabs">
            <li class="active"><a href="#creater_list" data-toggle="tab">投资机构列表</a></li>
            <li><a href="#new_creater" data-toggle="tab">添加投资机构</a></li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">

                <div class="row-fluid">
                    <div id="TabContent" class="tab-content">
                        <div class="tab-pane fade in active" id="creater_list">
                            <div class="row-fluid">
                                <div class="block span12">
                                    <a href="#tablewidget" class="block-heading" data-toggle="collapse">投资机构列表<span
                                                class="label label-warning">+{{count($orgs)}}</span></a>
                                    <div id="tablewidget" class="block-body collapse in">
                                        <table class="table">
                                            <thead>
                                            <tr>
                                                <th width="15%">机构名</th>
                                                <th width="15%">成立时间</th>
                                                <th width="15%">总资本</th>
                                                <th width="20%">投资范围</th>
                                                <th width="15%">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @if($orgs)
                                                @foreach($orgs as $org)
                                                    <tr>
                                                        <td>{{$org->invest_name}}</td>
                                                        <td>{{date('Y-m',strtotime($org->begin_date))}}</td>
                                                        <td>{{$org->invest_money}}</td>
                                                        <td>@if($org->minquato && $org->maxquato)
                                                                {{$org->minquato}}-{{$org->maxquato}}万
                                                            @else
                                                                暂无数据
                                                            @endif
                                                        </td>

                                                            <td>
                                                                <a class="edit" href="{{route('Admin.Users.editInvestOrgPage' , ['id'=>$org->id])}}">编辑</a>
                                                                <a href="javascript:;" class="del" data="{{$org->id}}">删除</a>
                                                            </td>

                                                    </tr>
                                                @endforeach
                                            @endif
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="pagination">
                                        <ul>
                                            {!! $orgs->render() !!}
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="tab-pane fade" id="new_creater">
                            <div class="container-fluid">
                                <div class="row-fluid">
                                <div class="well">
                                            <div id="myTabContent" class="tab-content">
                                                <form id="form_org" method="post">
                                                <div class="tab-pane active in" id="home">
                                                    <label>机构logo</label>
                                                    <em class="pro-name"></em><a class="logo" href="javascript:void(0);" id="inputImage"><img
                                                                id="org_logo_url" src="{{route('Api.Images.Show')}}"
                                                                title="点击上传logo" width="100" height="100" /></a><input
                                                            type="hidden" id="img_logo_id" value="0" /><em
                                                            class="msg"></em>
                                                    <label>机构名</label>
                                                    <input type="text" name="invest_name" class="input-xlarge">

                                                    <label>资金总量</label>
                                                    <input type="text" name="invest_money" class="input-xlarge">

                                                    <label>投资额度</label>
                                                    <input type="text" name="min_quota" class="input-xlarge">
                                                    <input type="text" name="max_quota" class="input-xlarge">

                                                    <label>网址</label>
                                                    <input type="text" name="web_link" class="input-xlarge">
                                                    <label>微信公众号</label>
                                                    <input type="text" name="wechat" class="input-xlarge">
                                                    <label>微博</label>
                                                    <input type="text" name="weibo" class="input-xlarge">
                                                    <label>成立时间</label>
                                                    <p id="dateOnlyExample">
                                                        <input type="text" name="begin_date" placeholder="请选择开始时间" class="date" />
                                                    </p>
                                                        <label>机构描述</label>
                                                    <textarea name="user_desc" rows="5" style="width:500px;" 
                                                              class="input-xlarge"></textarea>
                                                    <input type="hidden" name="user_id" value="0">

                                                </div>

                                            <div class="btn-toolbar">
                                                <button type="button" class="btn btn-primary save_org"><i class="icon-save"></i>
                                                    保存</button>
                                                <a href="#myModal" data-toggle="modal" class="btn">取消</a>
                                                <div class="btn-group">
                                                </div>
                                            </div>
                                            </form>
                                        </div>


                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

        </div>
    </div>

<script>
    var EditInvestOrg       =   "{{route('Api.InvestOrg.EditInvestOrg' ,['id'=>0])}}" ;
    var DelInvestOrgById    =   "{{route('Api.Admin.DelInvestOrgById')}}" ;
</script>

<script src="{{url('/js/admin/users.org.js')}}"></script>
<link href="{{url('js/lib/time/bootstrap-datepicker.css')}}" type="text/css" rel="stylesheet"/>
<script src="{{url('js/lib/time/bootstrap-datepicker.js')}}"></script>
<script>
    $('#dateOnlyExample .date').datepicker({
        'format': 'yyyy-m-d',
        'autoclose': true
    });
</script>

        <script>
    /** 头像上传 */
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'inputImage',
        url: '{{ url('api/upload/image')  }}',

        chunk_size: '2mb',
        filters: {
            max_file_size: '10mb',
            mime_types: [
                {title: "Image files", extensions: "jpg,gif,png"}
            ],
            prevent_duplicates: false
        },
        multi_selection: true,
        unique_names: true,

        flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
        silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

        file_data_name: 'photo',
        headers: {
            Accept: 'application/json'
        },

        multipart_params: {
            _token: '{{ csrf_token() }}'
        },

        init: {
            PostInit: function () {
            },

            FilesAdded: function (up, files) {
                up.start();
            },

            BeforeUpload: function (up, file) {
                up.settings.multipart_params.file_name = file.name;
            },

            UploadProgress: function (up, file) {
                $('.msg').html('上传中...');
            },

            Error: function (up, err) {
                var responseObj = '', responseMessage = '';
                try {
                    responseObj = $.parseJSON(err.response);
                    responseMessage = responseObj.message;
                } catch ($e) {

                }

                noty({
                    type: 'error',
                    text: err.message + ' ' + responseMessage,
                    callback: {
                        afterClose: function () {
                            $('#inputImage').show();
                            $('#inputImageProgress').hide();
                        }
                    }
                });
            },

            FileUploaded: function (up, file, info) {
                var responseObj = '', responseMessage = '';
                try {
                    responseObj = $.parseJSON(info.response);
                    responseMessage = responseObj.message;
                } catch ($e) {

                }

                var $inputImage = $('.msg');
                $inputImage.html('上传成功！');
                $inputImage.show();

                var imageUrl = '', imageId = 0;
                if (responseObj && responseObj.data) {
                    var d = new Date();
                    imageUrl = "{{route('Api.Images.Show')}}?"+d.getTime();
                    imageId = responseObj.data.id;
                }
                $('#org_logo_url').attr('src', imageUrl);
                if(imageId !== null){
                    $('#logo_img_id').val(imageId);
                }else{
                    $('#logo_img_id').val('0');
                }
            }
        }
    });
    uploader.init();
</script>

@endsection


